const express = require("express")
const app = express()

const Vue = require("vue")
const {
  createRenderer
} = require("vue-server-renderer")

const renderer = createRenderer()

app.get('/', async (req, res) => {

  const vm = new Vue({
    data: {
      name: 'nick'
    },
    template: '<div>{{name}}</div>'
  })

  try {
    // renderToString将Vue实例转换为HTML字符串
    const html = await renderer.renderToString(vm)
    console.log(html);
    res.send(html)

  } catch (error) {
    res.status(500).send('Internal Server Error 500!')
  }

})

app.listen(3000)